home *** CD-ROM | disk | FTP | other *** search
/ Apple Developer Connection 1998 Fall: Game Toolkit / Disc.iso / SDKs / Apple Game Sprockets / NetSprocket / NewNSpTest Sources / aevt.c next >
Encoding:
C/C++ Source or Header  |  1997-09-18  |  5.1 KB  |  203 lines  |  [TEXT/CWIE]

  1. /*************************************************************************************
  2. #
  3. #        aevt.c
  4. #
  5. #        Apple events handler.
  6. #
  7. #        Author(s):     Michael Marinkovich
  8. #                    Apple Developer Technical Support
  9. #                    marink@apple.com
  10. #
  11. #        Modification History: 
  12. #
  13. #            2/10/96        MWM     Initial coding                     
  14. #
  15. #        Copyright © 1992-96 Apple Computer, Inc., All Rights Reserved
  16. #
  17. #
  18. #        You may incorporate this sample code into your applications without
  19. #        restriction, though the sample code has been provided "AS IS" and the
  20. #        responsibility for its operation is 100% yours.  However, what you are
  21. #        not permitted to do is to redistribute the source as "DSC Sample Code"
  22. #        after having made changes. If you're going to re-distribute the source,
  23. #        we require that you make it clear in the source that the code was
  24. #        descended from Apple Sample Code, but that you've made changes.
  25. #
  26. *************************************************************************************/
  27.  
  28. #include <AppleEvents.h>
  29. #include <Windows.h>
  30.  
  31. #include "App.h"
  32. #include "Proto.h"
  33.  
  34.  
  35. extern Boolean            gDone;
  36.  
  37. AEEventHandlerUPP        gAEOpenUPP;
  38. AEEventHandlerUPP        gAEQuitUPP;
  39. AEEventHandlerUPP        gAEOpenDocUPP;
  40. AEEventHandlerUPP        gAEPrintDocUPP;
  41.  
  42.  
  43. //----------------------------------------------------------------------
  44. //
  45. //    AEInit - initialize all the core apple events
  46. //
  47. //
  48. //----------------------------------------------------------------------
  49.  
  50. OSErr AEInit(void)
  51. {    
  52.     OSErr        err = noErr;
  53.  
  54.     gAEOpenUPP         = NewAEEventHandlerProc(DoAEOpenApp);
  55.     gAEQuitUPP         = NewAEEventHandlerProc(DoAEQuitApp);
  56.     gAEOpenDocUPP    = NewAEEventHandlerProc(DoAEOpenDoc);
  57.     gAEPrintDocUPP    = NewAEEventHandlerProc(DoAEPrintDoc);
  58.     
  59.                                 //    install auto Open App
  60.     err = AEInstallEventHandler(kCoreEventClass, kAEOpenApplication, 
  61.                                 gAEOpenUPP, 0L, false );
  62.                                                     
  63.     if (err == noErr)            // install auto Quit App
  64.         err = AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, 
  65.                                     gAEQuitUPP, 0L, false );
  66.         
  67.     if (err == noErr)            // install auto Open Document
  68.         err = AEInstallEventHandler(kCoreEventClass,kAEOpenDocuments,
  69.                                     gAEOpenDocUPP,0L,false);
  70.                                                         
  71.     if (err == noErr)            // install auto Print Document
  72.         err = AEInstallEventHandler(kCoreEventClass,kAEPrintDocuments,
  73.                                     gAEPrintDocUPP,0L,false);
  74.     
  75.                             
  76.     return err;
  77.                                                 
  78. }
  79.  
  80.  
  81. //----------------------------------------------------------------------
  82. //
  83. //    AERemove - remove all the allocated apple events
  84. //
  85. //
  86. //----------------------------------------------------------------------
  87.  
  88. OSErr AERemove(void)
  89. {    
  90.     OSErr        err = noErr;
  91.  
  92.     // deallocate all the core AppleEvents and assume that they are still around 
  93.     // since we shouldn't have removed them before now.
  94.     err = AERemoveEventHandler(kCoreEventClass, kAEOpenApplication, gAEOpenUPP, false);
  95.     err = AERemoveEventHandler(kCoreEventClass, kAEQuitApplication, gAEQuitUPP, false);
  96.     err = AERemoveEventHandler(kCoreEventClass, kAEOpenDocuments, gAEOpenDocUPP, false);
  97.     err = AERemoveEventHandler(kCoreEventClass, kAEPrintDocuments, gAEPrintDocUPP, false);
  98.  
  99.     DisposeRoutineDescriptor(gAEOpenUPP);
  100.     DisposeRoutineDescriptor(gAEQuitUPP);
  101.     DisposeRoutineDescriptor(gAEOpenDocUPP);
  102.     DisposeRoutineDescriptor(gAEPrintDocUPP);
  103.  
  104. }
  105.  
  106.  
  107. //----------------------------------------------------------------------
  108. //
  109. //    DoAEOpenApp - called by the Finder at launch time
  110. //
  111. //
  112. //----------------------------------------------------------------------
  113.  
  114. pascal OSErr DoAEOpenApp(AppleEvent *event,AppleEvent reply,long refCon)
  115. {
  116.                         
  117.     return noErr;
  118.         
  119. }
  120.  
  121.  
  122. //----------------------------------------------------------------------
  123. //
  124. //     DoAEQuitApp -    called when the Finder asks app to quit
  125. //
  126. //
  127. //----------------------------------------------------------------------
  128.  
  129. pascal OSErr DoAEQuitApp(AppleEvent *event,AppleEvent reply,long refCon)
  130. {
  131.     #pragma unused( event, reply, refCon )
  132.  
  133.     // set the global quit flag
  134.     gDone = true;
  135.     
  136.     return noErr;
  137.         
  138. }
  139.  
  140.  
  141. //----------------------------------------------------------------------
  142. //
  143. //    DoAEOpenDoc - called when the Finder asks app to open a document
  144. //
  145. //
  146. //----------------------------------------------------------------------
  147.  
  148. pascal OSErr DoAEOpenDoc(AppleEvent *event,AppleEvent reply,long refCon)
  149. {
  150.     #pragma unused( event, reply, refCon )
  151.     
  152.  
  153.     return noErr;
  154.  
  155. }
  156.                 
  157.                                         
  158. //----------------------------------------------------------------------
  159. //
  160. //    DoAEPrintDoc - called when the Finder asks app to print a document
  161. //
  162. //
  163. //----------------------------------------------------------------------
  164.  
  165. pascal OSErr DoAEPrintDoc(AppleEvent *event,AppleEvent reply,long refCon)
  166. {
  167.     #pragma unused( event, reply, refCon )
  168.     
  169.  
  170.     return noErr;
  171.  
  172. }
  173.  
  174.  
  175. //----------------------------------------------------------------------
  176. //
  177. //    GotAEParams - make sure we got proper AE params for an Open 
  178. //                  Document from the Finder
  179. //
  180. //----------------------------------------------------------------------
  181.  
  182. OSErr GotAEParams(AppleEvent *appleEvent)
  183. {
  184.     OSErr            err;
  185.     DescType        type;
  186.     Size            size;
  187.     
  188.     err = AEGetAttributePtr(appleEvent,keyMissedKeywordAttr,
  189.                             typeWildCard,&type,nil,0,&size);
  190.                                             
  191.     if (err == errAEDescNotFound)
  192.         return(noErr);
  193.     
  194.     else
  195.     {
  196.         if (err == noErr)
  197.             return(errAEEventNotHandled);
  198.     }
  199.     
  200.     return err;
  201.  
  202.